//
//  MYBaseNavController.m
//  MYChatting
//
//  Created by mac on 16/8/29.
//  Copyright © 2016年 lhf. All rights reserved.
//

#import "MYBaseNavController.h"

@interface MYBaseNavController ()<UIGestureRecognizerDelegate>

@end

@implementation MYBaseNavController


- (void)viewDidLoad{
    [super viewDidLoad];
    
    self.interactivePopGestureRecognizer.delegate = self;
}


- (void)pushViewController:(nonnull UIViewController *)viewController animated:(BOOL)animated{
    
    if ([[self childViewControllers] count] != 0) {
        UIButton *btn = [[UIButton alloc] init];
        [btn setTitle:@"返回" forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:14];
        [btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"navigationbar_back_withtext"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
        viewController.hidesBottomBarWhenPushed = YES;
    }
  
    [super pushViewController:viewController animated:animated];
}


- (void)back{
    [self popToRootViewControllerAnimated:YES];
}


- (BOOL)gestureRecognizerShouldBegin:(nonnull UIGestureRecognizer *)gestureRecognizer{
    NSLog(@"你好的，天天快乐");
    return [[self childViewControllers] count] != 1;
}

@end
